<?php
/*
	结算明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$this->setting=$this->plugin_setting('sanset');
	if($this->setting['mid']!=$_SESSION['uid']){
		exi('你不是三方管理员！','error','/index/');
	}
	$return['setting']=$this->plugin_setting('page_setting');
	$status=intval($_RQ['status']);
	$return['balance_total']=price($this->sum('balance',array('mid'=>$_SESSION['uid']),'money'));
	$return['params']=array(
		'page'=>1,
		'status'=>$status?:3,
	);
	$return['list']=array();
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$wxapppay_types=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$wxapppay_types[]=array(
				'key'=>'credit',
				'title'=>$this->pay_types['credit'],
			);
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$wxapppay_types[]=array(
				'key'=>'wechat',
				'title'=>$this->pay_types['wechat'],
			);
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$wxapppay_types[]=array(
				'key'=>'alipay',
				'title'=>$this->pay_types['alipay'],
			);
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$wxapppay_types[]=array(
				'key'=>'union',
				'title'=>$this->pay_types['union'],
			);
			$pay_type=$pay_type?:'union';
		}
		$check=strstr($this->setting['withdrawtype'],'downline');
		if($check){
			$withdrawtype['downline']=$this->pay_types['downline'];
			$wxapppay_types[]=array(
				'key'=>'downline',
				'title'=>$this->pay_types['downline'],
			);
			$pay_type=$pay_type?:'downline';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$wxapppay_types=array();
	foreach($return['pay_types'] as $k=>$pv){
		$wxapppay_types[]=array(
			'key'=>$k,
			'title'=>$pv,
		);
	}
	$return['wxapppay_types']=$wxapppay_types;
	$check=strstr($this->setting['withdrawtype'],'alipay');
	if($check){
		$type_array[1]='提现到支付宝';
        $post1=$this->get('balance',array('pay_type'=>'alipay','mid'=>$_SESSION['uid']),array('alipay','realname'),'id desc');
	}
	$check=strstr($this->setting['withdrawtype'],'union');
	if($check){
		$type_array[2]='提现到银行卡';
        $post2=$this->get('balance',array('pay_type'=>'union','mid'=>$_SESSION['uid']),array('bankname','bankcard','realname'),'id desc');
        $post2['bankcard1']=$post2['bankcard'];
	}
    if($post1 || $post2) {
        $return['post'] = array_merge($post1, $post2);
    }
	$return['post']['id']=0;
	$return['post']['pay_type']=$pay_type;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid']);	
	$params['status']=intval($_RQ['status']);
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('balance',$parameter);
	$paytype=$this->pay_types;
	if(!$list){
		exi('none');
	}
	foreach($list as &$v){
		$v['newpay_type']=$v['pay_type'];
		$v['pay_type']=$paytype[$v['pay_type']];
		$v['pay_time']=date('Y-m-d H:i:s',$v['pay_time']);
	}
	exi($list);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$balance_id=intval($post['id']);
	$remark=$post['remark'];
	if($post['newpay_type']){
		$update=array(
			'status'=>0,
			'pay_type'=>$post['pay_type'],
			'realname'=>$post['realname'],
			'alipay'=>$post['alipay'],
			'bankname'=>$post['bankname'],
			'bankcard'=>$post['bankcard'],
			'wechat'=>$post['wechat'],
			'mobile'=>$post['mobile'],
			'remark'=>$remark,
		);
	}else{
		$update=array(
			'status'=>0,
			'remark'=>$remark,
		);
	}
	$this->update('balance',$update,array('id'=>$balance_id));
	exi('申请成功！','','main');
}
?>